package com.chis.netty.http.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpResponse;

import java.nio.charset.Charset;

public class HttpClientMsgHandler extends SimpleChannelInboundHandler<FullHttpResponse> {


    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) throws Exception {
//        if (!response.headers().isEmpty()) {
//            for (CharSequence name : response.headers().names()) {
//                for (CharSequence value : response.headers().getAll(name)) {
//                    System.err.println("HEADER: " + name + " = " + value);
//                }
//            }
//            System.err.println();
//        }
        System.err.println(response.content().toString(Charset.forName("utf-8")));
    }
}
